<template>
	<view>
		<u-tabs :list="list" :is-scroll="false" :current="current" @change="sectionChange"></u-tabs>
		<u-card padding="16" v-for="item in dataList2" :key="item.id" v-if="current == 0">
			<view class="" slot="head">
				<view class="wrap">
					<u-row>
						<u-col span="12" text-align="center">
							<view class="u-line-1 weikaishi2">
								<span>{{item.warehouseName+item.areaName+'-'+item.positionNumber}}</span>
							</view>
						</u-col>
						<u-col span="6" text-align="left">
							<view class=" jinxingzhong weikaishi3">
								<span>托盘：{{item.trayNumber}}</span>
							</view>
						</u-col>
						<u-col span="6" text-align="left">
							<view class="u-line-1  weikaishi3">
								<span>类型：{{item.panType}}</span>
							</view>
						</u-col>
						<u-col span="12" text-align="left">
							<view class=" jinxingzhong weikaishi3">
								<span>商品：{{item.goodsName}},{{item.goodsNo}}</span>
							</view>
						</u-col>
					</u-row>
				</view>
			</view>
			<view class="" slot="body">
				<view class="wrap">
					<u-row>
						<u-col span="6" text-align="left">
							<view class="u-line-1 u-m-t-4 weikaishi4">
								<span>库存数：{{item.num}}件</span>
							</view>
						</u-col>
						<u-col span="6" text-align="left">
							<view class="u-line-1 u-m-t-4 lanse weikaishi4">
								<span>盘点数：{{item.trueNum}}件</span>
							</view>
						</u-col>
						<u-col span="6" text-align="left">
							<view class=" u-m-t-4 weikaishi6">
								<span>批次：{{item.goodsbatchs}}</span>
							</view>
						</u-col>
						<u-col span="6" text-align="left">
							<view class=" u-m-t-4 lanse weikaishi6">
								<span>盘点：{{item.newgoodsbatchs}}</span>
							</view>
						</u-col>
						<u-col span="6" text-align="left">
							<view class="u-m-t-4 weikaishi6">
								<span>盘点人员：{{item.createUsername}}</span>
							</view>
						</u-col>
						<u-col span="6" text-align="left">
							<view class="u-m-t-4 lanse weikaishi6">
								<span>盘点时间：{{item.createTime}}</span>
							</view>
						</u-col>
						<u-col span="12" text-align="left">
							<view class="u-m-t-4 weikaishi6">
								<span>盘点描述：{{item.pandianNodes}}</span>
							</view>
						</u-col>
					</u-row>
				</view>
			</view>
			<view class="foot-butten" slot="foot">
				<view :class="flex">
					<u-col span="6" text-align="center" @click="findGoodsfenbu(item.goodsId)" >
						<view  class="u-m-10 u-border-right">
							查看商品分布
						</view>
					</u-col>
					<u-col span="6" text-align="center" @click="chuli(item.id)" >
						<view class="u-m-10 lanse">
							处理
						</view>
					</u-col>
				</view>
			</view>
		</u-card>
		<u-card padding="16" v-for="item in dataList" :key="item.id" v-if="current == 1">
			<view class="" slot="head">
				<view class="wrap">
					<u-row>
						<u-col span="12" text-align="center">
							<view class="u-line-1 u-m-t-2 weikaishi2">
								<span>{{item.warehouseName+item.areaName+'-'+item.positionNumber}}</span>
							</view>
						</u-col>
						<u-col span="6" text-align="left">
							<view class="u-line-1 u-m-t-2 weikaishi3 yiwancheng">
								<span>托盘：{{item.trayNumber}}</span>
							</view>
						</u-col>
						<u-col span="6" text-align="left">
							<view class="u-line-1 u-m-t-4 weikaishi3">
								<span>类型：{{item.panType}}</span>
							</view>
						</u-col>
						<u-col span="12" text-align="left">
							<view class=" u-m-t-4 weikaishi3 yiwancheng">
								<span>商品：{{item.goodsName}},{{item.goodsNo}}</span>
							</view>
						</u-col>
					</u-row>
				</view>
			</view>
			<view class="" slot="body">
				<view class="wrap">
					<u-row>
						<u-col span="6" text-align="left">
							<view class="u-line-1 u-m-t-4 weikaishi4">
								<span>库存数：{{item.num}}</span>
							</view>
						</u-col>
						<u-col span="6" text-align="left">
							<view class="u-line-1 u-m-t-4 lanse weikaishi4">
								<span>盘点数：{{item.trueNum}}</span>
							</view>
						</u-col>
						<u-col span="6" text-align="left">
							<view class="u-line-1 u-m-t-4 weikaishi6">
								<span>批次：{{item.goodsbatchs}}</span>
							</view>
						</u-col>
						<u-col span="6" text-align="left">
							<view class="u-line-1 u-m-t-4 lanse weikaishi6">
								<span>盘点：{{item.newgoodsbatchs}}</span>
							</view>
						</u-col>
						<u-col span="6" text-align="left">
							<view class="u-m-t-4 weikaishi6">
								<span>盘点人：{{item.createUsername}}</span>
							</view>
						</u-col>
						<u-col span="6" text-align="left">
							<view class="u-m-t-4 lanse weikaishi6">
								<span>盘点时间：{{item.createTime}}</span>
							</view>
						</u-col>
						<u-col span="12" text-align="left">
							<view class=" u-m-t-4 weikaishi6">
								<span>盘点描述：{{item.pandianNodes}}</span>
							</view>
						</u-col>
						<u-col span="6" text-align="left">
							<view class=" u-m-t-4 weikaishi6">
								<span>处理人：{{item.dealPerson}}</span>
							</view>
						</u-col>
						<u-col span="6" text-align="left">
							<view class="u-m-t-4 lanse weikaishi6">
								<span>处理时间：{{item.dealTime}}</span>
							</view>
						</u-col>
						<u-col span="12" text-align="left">
							<view class=" u-m-t-4 weikaishi6">
								<span>处理描述：{{item.nodes}}</span>
							</view>
						</u-col>
					</u-row>
				</view>
			</view>
		</u-card>
		
		<u-popup v-model="popupShow2" mode="center" closeable width="550rpx" height="600rpx" border-radius="10">
			<view class="u-text-center u-m-t-15 weikaishi3"><u-icon name="search" size="30" labelSize="15px" labelColor="#000000" label="货物位置"></u-icon></view>
			<u-card padding="16">
				<view class="" slot="head">
					<view class="wrap">
						<u-row>
							<u-col span="12">
								<view class="weikaishi4 lanse">
									<span  v-if="kucunlist.length > 0" v-html="kucunlist[0].goodsName"></span>
								</view>
							</u-col>
						</u-row>
					</view>
				</view>
				<view class="" slot="body">
					<view class="wrap">
						<u-row >
							<u-col span="3" text-align="center">
								<view class="u-line-1 u-m-t-10 weikaishi">
									<span>库位</span>
								</view>
							</u-col>
							<u-col span="4" text-align="center">
								<view class="u-line-1 u-m-t-10 weikaishi">
									<span>数量</span>
								</view>
							</u-col>
							<u-col span="5" text-align="center">
								<view class="u-line-1 u-m-t-10 weikaishi">
									<span>批次</span>
								</view>
							</u-col>
						</u-row>
						<u-row v-for="(item1,index1) in kucunlist" :key="index1">
							<u-col span="3" text-align="center">
								<view class="u-line-1 u-m-t-15 weikaishi6">
									<span>{{item1.positionNumber}}</span>
								</view>
							</u-col>
							<u-col span="4" text-align="center">
								<view class="u-line-1 u-m-t-15 weikaishi7">
									<span>{{item1.num}}</span>
								</view>
							</u-col>
							<u-col span="5" text-align="center">
								<view class="u-line-1 u-m-t-15 weikaishi7">
									<span>{{item1.goodsbatchs}}</span>
								</view>
							</u-col>
						</u-row>
					</view>
				</view>
			</u-card>
		</u-popup>
		
		<u-popup v-model="show" mode="center" closeable width="600rpx" height="350rpx" border-radius="10">
			<view class="u-text-center u-m-t-20">处理异常</view>
			<view class=" u-m-20">
				<u-input v-model="nodes" type="textarea" border="true" placeholder="请输入异常描述"/>
			</view>
			<view style="height: 80rpx;text-align: center;">
				<view class="close-btn u-m-t-40">
					<u-button size="medium" @click="define4()">确定</u-button>
				</view>
			</view>
		</u-popup>
		<view>
			<u-toast ref="uToast" />
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				flex:'',
				list: [
					{
						name: '待处理'
					}, 
					{
						name: '已处理'
					},
				],
				current: 0,
				dataList:[],
			    pageNo: 1,
			    hasMore: true,
			    orderCount: 0,
				dataList2:[],
				popupShow2:false,
				kucunlist:[],
				show:false,
				currentid:'',
				nodes:'',
			};
		},
		onLoad() {
			//#ifdef H5 || APP-PLUS
			this.flex = 'u-flex'
			//#endif
			this.refresh()
			this.finddaichuli()
		},
		onPullDownRefresh() {
			if(this.current == 0){
				this.finddaichuli()
			} else {
				this.refresh()
			}
			uni.stopPullDownRefresh()
		},
		onReachBottom() {
			if(this.current == 1){
				uni.showLoading({
					title: '加载中'
				})
				if (this.hasMore) {
					this.pageNo++ 
					setTimeout(() => {
						this.loadOrder({
						}).then(res => {})
						uni.hideLoading()
					}, 500)
				} else {
					setTimeout(() => {
						uni.hideLoading()
						uni.showToast({
							icon: 'none',
							title: '已经到低了哦',
							duration: 2000
						});
					}, 500)
				}
			}
		},
		methods:{
			define4(){
				this.$http.post('/rest/ChouPan/deleteList',{
				},{
					params: {
						id:this.currentid,
						nodes:this.nodes
					},
					header: {
						'Authorization' :uni.getStorageSync('token'),
					}
				}).then(res => {
					if(res.data.code == 200) {
						this.$refs.uToast.show({
							title: '操作成功',
							type: 'success'
						})
						this.finddaichuli()
						this.refresh()
						this.show = false
					} else {
						this.$refs.uToast.show({
							title: res.data.message,
							type: 'error'
						})
						this.finddaichuli()
						this.refresh()
					}
				})
			},
			findGoodsfenbu(goodsId){
				this.$http.post('/rest/ChouPan/kucunlist',{
				},{
					params: {
						goodsId:goodsId
					},
					header: {
						'Authorization' :uni.getStorageSync('token'),
					}
				}).then(res => {
					this.kucunlist = res.data.data
					this.popupShow2 = true
				})
			},
			chuli(id){
				this.currentid = id
				this.show = true
			},
			finddaichuli(){
				this.$http.post('/rest/ChouPan/appabnormalliststaylist',{
				},{
					params: {
					},
					header: {
						'Authorization' :uni.getStorageSync('token'),
					}
				}).then(res => {
					this.dataList2 = res.data.data
				})
			},
			sectionChange(e){
				this.current = e
			},
			refresh(){
				this.pageNo = 1
				this.hasMore = true
				this.loadOrder({
				}).then(res => {
				})
			},
			loadOrder(param = {}) {
				return new Promise((resolve, reject) => {
					param = Object.assign(param, {
						page: this.pageNo,
						limit: 10
					})
					this.$http.post('/rest/ChouPan/appDeletelist',{
					},{
						params: param,
						header: {
							'Authorization' :uni.getStorageSync('token'),
						}
					}).then(res => {
						if (this.pageNo == 1) {
							this.dataList = res.data.data
						} else {
							this.dataList = this.dataList.concat(res.data.data)
						}
						this.orderCount = res.data.count
						this.hasMore = this.pageNo * 10 < res.data.count
						resolve(res)
					})
				})
			},
		}
	}
</script>

<style lang="scss">
	.u-body-item {
		padding: 20rpx 15rpx;
	}
	.wrap {
		padding: 0rpx 12rpx;
	}

	.u-row {
		margin: 10rpx 2rpx;
	}
	.weikaishi2{
		font-size: 34rpx;
	}
	.weikaishi3{
		font-size: 30rpx;
	}
</style>
